﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataAccessLayer
{
    public class StockHistoryRepository
    {
        StationeryInventoryEntities1 ent;

        public StockHistoryRepository()
        {
            ent = new StationeryInventoryEntities1();
        }

        #region Select Method

        public StockHistory GetStockHistoryByStockHistoryID(int stockHistoryId)
        {
            StockHistory stockHistory = new StockHistory();

            var stock = ent.StockHistories.FirstOrDefault(x => x.StockHistoryID == stockHistoryId);

            if (stock != null)
            {
                stockHistory = stock;
            }
            return stockHistory;
        }

        #endregion

        #region Create Method

        public void CreateStockHistory(StockHistory stockHistory)
        {
            ent.StockHistories.Add(stockHistory);
            ent.SaveChanges();
        }

        #endregion

        #region Update Method

        public void UpdateStockHistory(StockHistory stockHistory)
        {
            var stock = ent.StockHistories.FirstOrDefault(x => x.StockHistoryID == stockHistory.StockHistoryID);

            stock.ItemCode = stockHistory.ItemCode;
            stock.Date = stockHistory.Date;
            stock.Description = stockHistory.Description;
            stock.AdjustedQty = stockHistory.AdjustedQty;
            stock.Balance = stockHistory.Balance;

            ent.SaveChanges();

        }

        #endregion
    }
}
